using System.IO;

namespace ModelGenerator.ModelGenerator
{
    public class FileMover
    {
        /// <summary>
        /// Moves the code.
        /// </summary>
        /// <param name="startlocation">The startlocation.</param>
        /// <param name="endlocation">The endlocation.</param>
        /// <param name="filePath">The file path.</param>
        /// <param name="className">Name of the class.</param>
        /// <param name="targetDirectory">The target directory.</param>
        /// <param name="TargetNamespace">The target namespace.</param>
        public static void moveCode(int startlocation, int endlocation, string filePath, string className,
                                    string targetDirectory, string TargetNamespace)
        {
            var reader = new StreamReader(filePath);
            for (int i = 0; i < startlocation - 1; i++)
            {
                reader.ReadLine();
            }

            var path = string.Format(@"{0}\{1}.cs", targetDirectory, className);
            if (File.Exists(path))
                File.Delete(path);
            var writer = new StreamWriter(path);

            writer.WriteLine("using System;");
            writer.WriteLine("using System.Collections.Generic;");
            writer.WriteLine("using Castle.ActiveRecord;");
            writer.WriteLine();
            writer.WriteLine("namespace {0}", TargetNamespace);
            writer.WriteLine("{");

            for (int i = 0; i <= endlocation - startlocation; i++)
            {
                writer.WriteLine(reader.ReadLine());
            }

            writer.WriteLine("}");

            reader.Close();
            writer.Close();
        }
    }
}